package com.bawei.a2010kotlin.room

import androidx.room.Database
import androidx.room.DatabaseConfiguration
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import com.bawei.a2010kotlin.App

//抽象类
@Database(entities = [Student::class], version = 1, exportSchema = true)
abstract class AppDataBase:RoomDatabase() {
    abstract fun getStudentDao():StudentDao
    companion object{
        private var instance:AppDataBase? = null  //可以为空
        fun getAppDataBase() : AppDataBase?{
            if(instance == null){
                synchronized(AppDataBase::class){
                    if(instance == null){
                        instance = Room.databaseBuilder(App.instance,AppDataBase::class.java,"student.db")
                            .allowMainThreadQueries()
                            .build()
                    }
                }
            }
            return instance
        }
    }

}